/*
 Reverse digits of an integer.

 Example1: x = 123, return 321
 Example2: x = -123, return -321
 */


/**
 * @param {number} x
 * @return {number}
 */
var reverse = function (x) {
    let num = x;
    let y = 0;
    while (num != 0) {
        y *= 10;
        y += num % 10;
        num = (num - num % 10) / 10;
    }
    if(y>Math.pow(2,31)|| y<Math.pow(2,31)*-1){
        return 0;
    }
    return y;
};

console.log(Math.pow(2,31));
console.log(reverse(-9874231));

